Ext.define('PJ.view.mytrainingprogram.List', {
    extend: 'AM.default.DefaultList',
    requires: ['AM.default.DefaultDateField', 
               'AM.default.DateTime', 
               'AM.default.DefaultSearchForm',
               'AM.default.jsonp.DefaultLoadJsonp'//jsonp加载数据
               ],
               
    //报名管理列表--中组部，部委
               
    initComponent: function(){
        var me = this;
        me.columns = [{
            header: '培训班编号',
            dataIndex: 'tc.class_Num',
            minWidth: 110,
    		renderer: function(value, meta, record){
    			meta.style = "white-space:normal;cursor: pointer;color:blue;";
    			meta.tdAttr = "data-qtip='" + value + "' classId=" + record.get("classId")+ " lockState=" + record.get("lockState");;
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
      				var classId = clm.getAttribute("classId");
      				var lockState=clm.getAttribute("lockState");
      				var type;
  					win = Ext.create('PJ.view.trainingmanagement.Look', {
      					title: "查看培训班",
      					flag:4,
      					grid: me,
      					classId:classId,
      					isHideExpectTime: false,
      					isDisable:false,
      					isReadOnly:true
      				}).show();
      				
      				var actionName = "load";
      				if(gj_onlineLearning_constant.loadType == "jsonp"){
      					actionName = "loadJsonp";
      				}
      				win.down("form").getForm().doAction(actionName,{
      					url:me.store.preUpdateUrl,
      					params:{
      						classId: classId
      					},
      					success:function(f,action){
      						var data = action.response.responseText;
      	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
      	        			var form = win.down('form');	 
      	        			var baseForm = form.getForm();
      	        			baseForm.findField("classNum").setValue(json.data.classNum);
      					}
      				});
      			}
    		}
        },{
            header: '培训班名称',
            dataIndex: 'tc.class_Name',
            flex: 1,
            minWidth: 110,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
        	header: '主办单位',
        	dataIndex: 'tc.sponsor_name',
            width: 120,
        	renderer: function(value, meta, record){
        		meta.tdAttr = "data-qtip='" + value + "'";
        		return value;
        	}
        },{
            header: '培训班类型',
            dataIndex: 'bb.DATA_CODE',
            width: 90,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '开班时间',
            dataIndex: 'tc.begin_Date',
            width: 110,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '结业时间',
            dataIndex: 'tc.end_Date',
            width: 90,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '报名开始时间',
            dataIndex: 'tc.enter_Begin_Time',
            width: 90,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '审核状态',
            dataIndex: 'tcu.auditing_State',
            width: 90,
            renderer: function(v, meta, record){
            	meta.style="padding-bottom: 0px;padding-top: 0px;line-height: 19px;padding-left: 0px;";
                var text = "",tipText="";
                if (v == 3) {
                	tipText="报名待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">报名待审核</div>';
                }
                else if (v == 1) {
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过</div>';
                	tipText="报名通过";
                }else if (v == 2) {
                	tipText="点击查看驳回原因";
                	text= '<div style="border-left:5px solid red;height:19px;cursor: pointer;padding-left:2px;"><span style="cursor: pointer;color:blue;">报名未通过</span></div>';
                }else if(v == 4){
                	tipText="撤销待审核";
                	text= '<div style="border-left:5px solid white;height:19px;padding-left:2px;">撤销待审核</div>';
                }else if(v == 5){
                	tipText="报名通过(撤销未通过)";
                	text= '<div style="border-left:5px solid green;height:19px;padding-left:2px;">报名通过(<span style="cursor: pointer;color:blue;">撤销未通过</span>)</div>';
                }
                meta.tdAttr = 'data-qtip="' + tipText + '" auditStatus=' + record.get("c.auditing_State") + ' classUserId=' + record.get("classUserId") + ' userId=' + record.get("userId");
                return text;
            }
        },{
            header: '心得下载',
            menuDisabled: true,
            sortable: false,
            resizable: false,
            hideable: false,
            align: 'center',
            xtype: 'actioncolumn',
            width: 90,
            items: [{
//              	tooltip: '下载附件',
            	getClass: function(v, meta, rec){
            		var attachmentID = rec.get('attachmentID');
            		if(!Ext.isEmpty(attachmentID)){
            			meta.style = "cursor: pointer;";
                		return 'myExperienceIco';
            		}
        		},
                handler: function(grid, rowIndex, colIndex, item, eve, record){
                    var store = grid.getStore();
                    var atag = Ext.get("exportResume");
                    atag.set({
                        "href": store.downloadUrl+'?attachmentID='+record.get('attachmentID')
                    });
                    atag.dom.click();
                }
            }]
        },{
            header: '问卷评估',
            menuDisabled: true,
            sortable: false,
            resizable: false,
            hideable: false,
            align: 'center',
            xtype: 'actioncolumn',
            width: 90,
            items: [{
//              	tooltip: '问卷评估',
            	getClass: function(v, meta, rec){
            		var questionnaireId = rec.get('questionnaireId');
            		if(!Ext.isEmpty(questionnaireId)){
            			meta.style = "cursor: pointer;";
                		return 'questionnaireIco';
            		}
        		},
                handler: function(grid, rowIndex, colIndex, item, eve, record){
                    var store = grid.getStore();
                    var atag = Ext.get("exportResume");
                    atag.set({
                        "href": store.questionnaireQRcodeUrl+'&searchClassId='+record.get('classId')+'&searchUserLoginId='+record.get('loginID')
                    });
                    atag.dom.click();
                }
            }]
        }];
        me.store = Ext.create('PJ.' + prototype + '.mytrainingprogram.List', {
            isLoad: false
        });
        me.loadType = gj_onlineLearning_constant.loadType;
        me.callParent(arguments);
    },
    /**
     * 报名审核
     */
    onApplicationAuditClick: function(){
		var me = this;
		var record = this.getSelectionModel().getSelection();
        if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		Ext.create('AM.default.DefaultWindowView', {
            title: "报名审核",
            height:510,
            width: 1055,
            grid: me,
			clickSource:1,
            classId: record[0].get("classId"),
            openState: record[0].get("tc.open_State"),
            items: [{
                xtype: 'applicationAuditList'
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
	/**
	 * 报名调整
	 */
	onRegistrationAdjustmentClick: function(){
    	var me = this;
        var records = me.getSelectionModel().getSelection();
    	if(records.length > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '只允许操作一条数据！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
    		return;
    	}
    	/*
        if (records[0].get("tc.open_State") ==3 || records[0].get("tc.publish_State") != 1) {
            Ext.Msg.show({
                title: '提示',
                msg: '只能对已发布且未结班的班级报名调整！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
            return;
        }
        */
		var win = Ext.create('PJ.view.mytrainingprogram.SignUpFrame', {
			grid: me,
			title: "代报名",
			width: 1200,
			height: 650,
			classId: records[0].get("classId"),
			openState: records[0].get("tc.open_State"),
			className:records[0].get('tc.class_Name'),
			endDate:records[0].get('tc.end_Date'),
			beginDate:records[0].get('tc.begin_Date'),
			publishState: records[0].get("tc.publish_State"),
			sponsorId:records[0].get("tc.sponsor_Id"),
			signUpState:2,
			auditingState:1,
			clickSource:1
		}).show();
//		var actionName = "load";
//        if(gj_onlineLearning_constant.loadType=="jsonp") {
//        	actionName= "loadJsonp";
//        }
//        win.down('form').getForm().doAction(actionName,{
//        	url: me.store.configurationUrl,
//            params: {
//            	classId: records[0].get("classId")//培训班ID
//            },
//            success:function(form,action){
//            	var data = action.response.responseText;
//    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
//    			var dateStar = json.data.beginDateStr;//举办时间（开始）
//    			var dateEnd = json.data.endDateStr;//举办时间（截止）
//    			var form = win.down('form');	 
//    			var baseForm = form.getForm();
//    			baseForm.findField("className").setValue(json.data.className);//班级名称
//    			baseForm.findField("learnTime").setValue(dateStar + ' 至 ' + dateEnd);
//            }
//        });
    },
    /**
     * 导出
     */
    onExportClick: function(num){
    	var me = this;
    	var store = me.getStore();
    	var params=store.proxy.extraParams;
    	var records = me.getSelectionModel().getSelection();
    	var str = "";
    	for(var i = 0;i<records.length;i++){
    		str += "&searchClassIds=" + records[i].get("classId");
    	}
    	var href=store.exportUrl + "?" + str + '&auditingState=1&clickSource=1';
    	for(var param in params){
    		if(params[param] === undefined){
    			href+="&"+param+"=";
    		}else{
    			href+="&"+param+"="+params[param];
    		}
    	}
    	href+="&expState="+num+"&searchSignUpState=1&searchSignUpState=5";
    	href = encodeURI(href);
    	var atag = Ext.get("exportResume");
    	atag.set({
    		"href": href
    	});
    	atag.dom.click();
    },
    /**
     * 调整名额
     */
    onAdjustTheQuotaClick: function(){
		var me = this;
		var record = this.getSelectionModel().getSelection();
        if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		Ext.create('AM.default.DefaultWindowView', {
            title: "调整名额",
            height:550,
            width: 650,
            grid: me,
            classId:record[0].get("classId"),
            items: [{
                xtype: 'adjustTheQuotaList'
                    }],
            buttons: [{
                text: '确定',
                scope: this,
                handler: function(button){
                	button.up('window').down('adjustTheQuotaList').sub();
                }
            },{
                text: '关闭',
                scope: this,
                handler: function(button){
                	button.up('window').close();
                }
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
	//上传参训通知
  	onImportClick: function(){
  		var me = this;
  		var records = me.getSelectionModel().getSelection();
  		if(records.length > 1){
  			Ext.Msg.show({
  				title: '提示',
  				msg: '只允许操作一条数据！',
  				icon: Ext.Msg.WARNING,
  				buttons: Ext.Msg.OK
  			});
  			return;
  		}
  		Ext.create("PJ.view.mytrainingprogram.Upload", {
  			title: "上传学员心得",
  			height: 140,
  			width: 350,
  			grid: me,
  			classUserId: records[0].get('classUserId')
  		}).show();
      },
      onRemovetClick: function(){
    	  var me = this;
    	  var store = me.getStore();
    	  var records = me.getSelectionModel().getSelection();
    	  Ext.Msg.confirm({
      		  title:'提示',
      		  msg:'您确定要删除这些数据吗?',
      		  icon:Ext.Msg.WARNING,
      		  buttons:Ext.Msg.OKCANCEL,
      		  fn:function(id){
      			  if(id=='ok'){
      				  var attachmentIds= new Array();
      				  var classUserIds= new Array();
      				  Ext.Array.each(records,function(name,index){
      					attachmentIds.push(name.get('attachmentID'));
      					classUserIds.push(name.get('classUserId'));
      				  });
//      				  if(attachmentIds.length==0){
//      					Ext.Msg.show({
//      		  				title: '提示',
//      		  				msg: '所选附件已经删除！',
//      		  				icon: Ext.Msg.WARNING,
//      		  				buttons: Ext.Msg.OK
//      		  			});
//      		  			return;
//      				  }
  					  Ext.Ajax.request({
  						  url:store.deleteUrl,
  						  params: {
                			  attachmentIds: attachmentIds,
                			  classUserIds: classUserIds,
  							  submintType: 'activeStateToN'
  	                       },
  						  success:function(response){
  							  var data=response.responseText;
  							  var json=Ext.decode(data,true);
  							  if(json.success){
  								  Orchid.alert('提示','删除成功!',function(){
  									  store.load();
  								  });
  							  }else{
  								  Orchid.alert('提示',json.msg);
  							  }
  						  }
  					  });
      			  }
      		  }
      	  });
      },
    listeners: {
        //点击列表数据时显示按钮事件
    	selectionchange: function(selModel, selected){
//    		this.down('#' + this.oldId + "RegistrationAdjustment").setDisabled(selected.length === 0);//报名
//    		this.down('#' + this.oldId + "ApplicationAudit").setDisabled(selected.length === 0);//报名审核
    		//this.down('#' + this.oldId + "Export").setDisabled(selected.length === 0);//导出
//    		this.down('#' + this.oldId + "ViewSignup").setDisabled(selected.length === 0);//查看报名状态
    		//this.down('#' + this.oldId + "AdjustTheQuota").setDisabled(selected.length === 0);//调整名额
//    		this.down('#' + this.oldId + "EntryList").setDisabled(selected.length === 0);//导出培训班报名名单
    		this.down('#' + this.oldId + "BatchImportRegistration").setDisabled(selected.length === 0);//上传参训通知
    		this.down('#' + this.oldId + "RemoveRegistration").setDisabled(selected.length === 0);//上传参训通知
    	},
        viewready: function(){
        	var me = this;
        	//导出按钮集合
        	var exportMenu = Ext.create('Ext.menu.Menu', {
                items: [{
                    text: '全部报名名单',
	        		iconCls: 'entryListAllIco',
                    listeners: {
                        click: function(btn){
                        	me.onExportClick(1);
                    	}
                    }
                }, {
                    text: '培训班报名名单',
	        		iconCls: 'entryListIco',
	        		disabled: true,
	        		itemId: this.oldId + "EntryList",
                    listeners: {
                    	click: function(btn){
                    		me.onExportClick(2);
                    	}
                    }
                }]
            });
            this.addDocked([{
                dock: 'top',
                xtype: "searchform",
                columnCount: 3,
                fieldDefaults: {
                    xtype: "combo",
                    emptyText: "请选择",
                    editable: false,
                    queryMode: 'local',//'remote',//数据类型
                    valueField: 'value',
                    displayField: 'text',
                    
                    labelAlign: 'right',
                    labelWidth: 80,
                    maxLength: 100
                },
                items: [{
                    xtype: "textfield",
                    fieldLabel: '培训班编号',
                    name: "searchClassNum",
                    emptyText: "请输入培训班编号"
                }, {
                    xtype: "textfield",
                    fieldLabel: "培训班名称",
                    name: "searchClassName",
                    emptyText: "请输入培训班名称"
                }, {
                    xtype: "textfield",
                    fieldLabel: "主办单位",
                    name: "searchSponsorName",
                    emptyText: "请输入主办单位"
                }, {
    				xtype: 'defaultDate',
    				fieldLabel: '开班时间',
    				name: 'searchBeginDate',
    				id: 'searchBankQUSD_1',
    				vtype: 'startLessEndDate',
    				startLessEndDate: {
    					targetCmpId: 'searchBankQUED_1',
    					isStart: true
    				},
    				emptyText: "请输入开班时间"
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '结业时间:',
    				labelSeparator: '',
    				name: 'searchEndDate',
    				id: 'searchBankQUED_1',
    				vtype: 'startLessEndDate',
    				vtypeText: '结束时间不能早于开始时间！',
    				startLessEndDate: {
    					targetCmpId: 'searchBankQUSD_1',
    					isStart: false
    				},
    				emptyText: "请输入结业时间"
    			},/* {
                    fieldLabel: "审核状态",
                    name: "searchSignUpState",
                    store: Ext.create("Ext.data.ArrayStore", {
    					fields: ['value', 'text'],
    					data: [[1, '审核通过'], [2, '审核未通过'], [3, '未审核']]
    				})
                }, {
                    fieldLabel: "班级状态",
                    name: "searchOpenState",
                    store: Ext.create("Ext.data.ArrayStore", {
    					fields: ['value', 'text'],
    					data: [[1, '已开班'], [2, '未开班'], [3, '已结班']]
    				})
                }, {
                    fieldLabel: "报名状态",
                    name: "searchSignUpState",
                    store: Ext.create("Ext.data.ArrayStore", {
    					fields: ['value', 'text'],
    					data: [[1, '正在报名'], [2, '未开始'], [3, '报名结束']]
    				})
                },*/{
                	xtype:"combo",
                    fieldLabel: "培训班类型",
                    name: "searchClassType",
                    emptyText: "请选择",
    				labelAlign: 'right',
                	store: Ext.create("Ext.data.ArrayStore", {
                		singleton: true,
                		fields: [{
                			name: 'value',
                			mapping: "dataCode",
                			type: 'string'
                		}, {
                			name: 'text',
                			mapping: "dataName",
                			type: 'string'
                		}],
                		proxy: {
                			type: gj_onlineLearning_constant.loadType,
                			url: this.store.trainingClassTypeUrl + '?typeCode=pxblx',
                			reader: Ext.create('Ext.data.reader.Json', {
                				type: 'json',
                				root: 'data',
                				successProperty: 'success'
                			})
                		},
                		autoLoad: true
                	}),
        			valueField: 'value',
        			displayField: 'text',
        			editable: false,
        			defaultActive: false
                }],
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '上传心得',
                    iconCls: 'batchImportRegistrationIco',
                    itemId: this.oldId + "BatchImportRegistration",
                    disabled: true,
                    scope: this,
                    handler: this.onImportClick
				},{
                    text: '删除心得',
                    iconCls: 'deleteIco',
                    itemId: this.oldId + "RemoveRegistration",
                    disabled: true,
                    scope: this,
                    handler: this.onRemovetClick
				}, "->", "->", this.countSelectPanel]
            }]);
            // 触发权限过滤事件
            this.fireEvent("permission", this);
            var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {};
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
        },
        afterrender: function(){
            this.loadMask = new Ext.LoadMask(this, {
                msg: "正在加载中,请稍后...."
            });
        }
    }
});
